//
// Created by guanyicheng on 2022/9/14.
//
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
#include "../../common.h"
class Solution {
public:
    int findBottomLeftValue(TreeNode* root) {
        int res;
        deque<TreeNode*> dq{};
        dq.push_back(root);
        while (!dq.empty()) {
            res = dq.front()->val;
            int size = dq.size();
            while (size-- > 0) {
                TreeNode* t = dq.front();
                if (t->left) dq.push_back(t->left);
                if (t->right) dq.push_back(t->right);
                dq.pop_front();
            }
        }
        return res;
    }
};